perm filename EPAR3C.2[EAL,HE] blob
sn#713254 filedate 1983-06-01 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00005 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 {$NOMAIN Editor: Aux parsing routines }
C00025 00003 { Externally defined routines from elsewhere: }
C00029 00004 (* aux routines: declarationp, getDeclarations *)
C00048 00005 (* varParse & procParse *)
C00064 ENDMK
C⊗;
{$NOMAIN Editor: Aux parsing routines }
(* definition of record types & global variables used by AL *)
const
maxLines = 28;
maxPPLines = 18;
maxBpts = 25;
maxTBpts = 20; (* max could be exceeded by huge case stmnt *)
listinglength = 2000; (* Length of Listingarray *)
type
(* random type declarations for OMSI/SAIL compatibility *)
ascii = char;
atext = text;
byte = 0..255;
(* Here are all the pointer-type definitions. Since the various *)
(* records reference each other so much, we have to put them all here. *)
strngp = ↑strng;
statementp = ↑statement;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
tokenp = ↑token;
reswordp = ↑resword;
pdbp = ↑pdb;
linerecp = ↑linerec;
dump = ↑integer;
(* datatype definitions *)
datatypes = (pconstype, varitype, svaltype, vectype, rottype, transtype,
frametype, eventtype, strngtype, labeltype, proctype, arraytype,
reftype, valtype, cmontype, nulltype, undeftype,
dimensiontype, mactype, macargtype, freevartype);
scalar = real;
cstring = packed array [1..10] of ascii;
c4str = packed array [1..4] of ascii;
c5str = packed array [1..5] of ascii;
c20str = packed array [1..20] of ascii;
linestr = packed array [1..130] of ascii;
strng = record
next: strngp;
ch: cstring;
end;
(* statement definitions *)
stmntypes = (progtype, blocktype, coblocktype, endtype, coendtype,
fortype, iftype, whiletype, untiltype, casetype,
calltype, returntype,
printtype, prompttype, pausetype, aborttype, assigntype,
signaltype, waittype, enabletype, disabletype, cmtype,
affixtype, unfixtype,
movetype,jtmovetype,operatetype,opentype,closetype,centertype,
floattype, stoptype, retrytype,
requiretype, definetype, macrotype, commenttype, dimdeftype,
setbasetype, wristtype, saytype, declaretype, emptytype,
evaltype, armmagictype);
(* more??? *)
statement = packed record
next, last: statementp;
stlab: varidefp;
exprs: nodep; (* any expressions used by this statement *)
nlines: integer;
bpt,bad: boolean;
case stype: stmntypes of
progtype: (pcode: statementp; errors: integer);
blocktype,
declaretype,
endtype,
coendtype: (bcode, bparent: statementp; blkid: identp;
level, numvars: 0..255; variables: varidefp);
coblocktype: (threads: nodep; nthreads: integer; cblkid: identp);
returntype: (retval, rproc: nodep);
definetype: (macname,mpars: varidefp; macdef: tokenp);
dimdeftype: (dimname: varidefp; dimexpr: nodep);
end;
(* auxiliary definitions: variable, etc. *)
varidef = packed record
next,dnext: varidefp;
name: identp;
level: 0..255; (* environment level *)
offset: 0..255; (* environment offset *)
dtype: varidefp; (* to hold the dimension info *)
tbits: 0..15; (* special type bits: array = 1, proc = 2, ref = 4 & ? *)
dbits: 0..15; (* for use by debugger/interpreter *)
case vtype: datatypes of
arraytype: (a: nodep);
proctype: (p: nodep);
labeltype,
cmontype: (s: statementp);
mactype: (mdef: statementp);
macargtype: (marg: tokenp);
pconstype: (c: nodep);
dimensiontype: (dim: nodep);
end;
(* definition of the ubiquitous NODE record *)
nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
deprnode, viaptnode, apprnode, destnode, byptnode, durnode,
sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
arrivalnode, departingnode,
ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
calcnode, arraydefnode, bnddefnode, bndvalnode,
waitlistnode, procdefnode, tlistnode, dimnode, commentnode,
linearnode, elbownode, shouldernode, flipnode, wrtnode,
loadnode,velocitynode);
exprtypes = ( svalop, (* scalar operators *)
sltop, sleop, seqop, sgeop, sgtop, sneop, (* relations *)
notop, orop, xorop, andop, eqvop, (* logical *)
saddop, ssubop, smulop, sdivop, snegop, sabsop, (* scalar ops *)
sexpop, maxop, minop, intop, idivop, modop,
sqrtop, logop, expop, timeop, (* functions *)
sinop, cosop, tanop, asinop, acosop, atan2op, (* trig *)
vdotop, vmagnop, tmagnop,
vecop, (* vector operators *)
vmakeop, unitvop, vaddop, vsubop, crossvop, vnegop,
svmulop, vsmulop, vsdivop, tvmulop, wrtop,
tposop, taxisop,
transop, (* trans operators *)
tmakeop, torientop, ttmulop, tvaddop, tvsubop, tinvrtop,
vsaxwrop, constrop, ftofop, deproachop, fmakeop, vmkfrcop,
ioop, (* i/o operators *)
queryop, inscalarop,
specop, (* special operators *)
arefop, callop, grinchop, macroop, vmop, adcop, dacop, jointop,
badop,
addop, subop, negop, mulop, divop, absop); (* for parsing *)
leaftypes = pconstype..strngtype;
reltypes = sltop..sgtop;
forcetypes = (force,absforce,torque,abstorque,angvelocity);
node = record
next: nodep;
case ntype: nodetypes of
exprnode: (op: exprtypes; arg1, arg2, arg3: nodep; elength: integer);
leafnode: (case ltype: leaftypes of
varitype: (vari: varidefp; vid: identp);
pconstype: (cname: varidefp; pcval: nodep);
svaltype: (s: scalar; wid: integer);
vectype: (v: dump);
transtype: (t: dump);
strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
listnode: (lval: nodep);
clistnode: (cval: integer; stmnt: statementp; clast: nodep);
colistnode: (prev: nodep; cstmnt: statementp);
forvalnode: (fvar: dump; fstep: scalar);
errornode: (eexpr: nodep);
arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
bnddefnode: (lower, upper: nodep);
bndvalnode: (lb, ub, mult: integer);
procdefnode:(ptype: datatypes; level: 0..255;
pname, paramlist: varidefp; body: statementp);
end;
(* records for parser: ident, token, resword *)
ident = record
next: identp;
length: integer;
name: strngp;
predefined: varidefp;
end;
tokentypes = (reswdtype, identtype, constype, comnttype, delimtype, labeldeftype,
macpartype);
constypes = svaltype..strngtype;
reswdtypes = (stmnttype, filtype, clsetype, decltype, optype, edittype);
filtypes = (abouttype,alongtype,attype,bytype,defertype,dotype,elsetype,
errmodestype,fromtype,handtype,intype,nonrigidlytype,rigidlytype,
sourcefiletype,steptype,thentype,totype,untltype,viatype,
withtype,worldtype,zeroedtype,oftype,wheretype,nowaittype,
ontype,offtype,ppsizetype,collecttype,alltype,lextype,
notype,righttype,lefttype,uptype,downtype,motiontype);
clsetypes = (approachtype,arrivaltype,departuretype,departingtype,durationtype,
errortype,forcetype,forceframetype,forcewristtype,gathertype,
nildeproachtype,nullingtype,stiffnesstype,
torquetype,velocitytype,wobbletype,
cwtype,ccwtype,stopwaittimetype,angularvelocitytype,
respecttype,elbowtype,shouldertype,fliptype,lineartype,
jointspacetype,loadtype);
edittypes = (getcmd,savecmd,insertcmd,renamecmd,startcmd,gocmd,proceedcmd,
stepcmd,sstepcmd,nstepcmd,gstepcmd,executecmd,setcmd,tracecmd,
breakcmd,unbreakcmd,tbreakcmd,definecmd,markcmd,unmarkcmd,
popcmd,atcmd,calibratecmd);
token = record
next: tokenp;
case ttype: tokentypes of
constype: (cons: nodep);
comnttype: (len: integer; str: strngp);
delimtype: (ch: ascii);
reswdtype: (case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes) );
identtype: (id: identp);
labeldeftype: (lab: varidefp);
macpartype: (mpar: varidefp);
end;
resword = record
next: reswordp;
length: integer;
name: strngp;
case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes);
end;
(* process descriptor blocks & environment record definitions *)
queuetypes = (nullqueue,nowrunning,runqueue,inputqueue,eventqueue,sleepqueue,
forcewait,devicewait,joinwait,proccall);
pdb = packed record
nextpdb,next: pdbp; (* for list of all/active pdb's *)
level: 0..255; (* lexical level *)
mode: 0..255; (* expression/statement/sub-statement *)
priority: 0..255; (* probably never greater than 3? *)
status: queuetypes; (* what are we doing *)
env: dump;
spc: statementp; (* current statement *)
epc: nodep; (* current expression (if any) *)
sp: nodep; (* intermediate value stack *)
cm: dump; (* if we're a cmon point to our definition *)
mech: dump; (* current device being used *)
linenum: integer; (* used by editor/debugger *)
case procp: boolean of (* true if we're a procedure *)
true: (opdb: pdbp; (* pdb to restore when procedure exits *)
pdef: nodep); (* procedure definition node *)
false: (evt: dump; (* event to signal when process goes away *)
sdef: statementp); (* first statement where process was defined *)
end;
(* print related records: *)
cursorp = record
cline,ind: integer;
case stmntp: boolean of
true: (st: statementp);
false: (nd: nodep);
end;
linerec = record
next: linerecp;
start,length: integer
end;
listingarray = packed array [0..listinglength] of ascii;
(* global variables *)
var
(* from EDIT *)
listing: listingarray; (* first 150 chars are used by expression editor *)
(* next 40 by header & trailer lines *)
{*} cursorStack: array [1..15] of cursorp; {These are BIG records! }
lbuf: array [1..160] of ascii;
ppBuf: array [1..100] of ascii;
lines: array [1..maxLines] of linerecp; (* what's on the screen + some *)
ppLines: array [1..maxPPLines] of linerecp; (* for page printer *)
marks: array [1..20] of integer;
reswords: array [0..26] of reswordp;
idents: array [0..26] of identp;
macrostack: array [1..10] of tokenp;
curmacstack: array [1..10] of varidefp;
screenheight,dispHeight: integer;
ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
firstDline,topDline,botDline,firstLine,lastLine,curLine: integer;
freeLines,oldLines: linerecp;
sysVars: varidefp;
dProg: statementp;
curBlock, newDeclarations, findStmnt: statementp;
macrodepth: integer;
filedepth, errCount, sCursor: integer;
curChar, maxChar, curFLine, curPage: integer;
nodim, distancedim, timedim, angledim,
forcedim, torquedim, veldim, angveldim: varidefp;
fvstiffdim, mvstiffdim: nodep;
pnode: nodep;
smartTerminal: boolean; (* true = insert/delete, false = redraw line *)
setUp,setExpr,setCursor,dontPrint,outFilep,collect,fParse,sParse,
eofError,endOfLine,backup,expandmacros,flushcomments,checkDims,
shownLine: boolean;
curtoken: token;
file1,file2,file3,file4,file5,outFile: atext;
bpts: array [1..maxBpts] of statementp; (* debugging crap *)
tbpts: array [1..maxTBpts] of statementp;
debugPdbs: array [0..10] of pdbp;
nbpts,ntbpts,debugLevel: integer;
eCurInt: pdbp;
STLevel: integer; (* set by GO *)
singleThreadMode,tSingleThreadMode: boolean;
(* from INTERP *)
inputLine: array [1..20] of ascii;
talk: text; (* for using the speech synthesizer *)
curInt, activeInts, readQueue, allPdbs: pdbp;
(* sysEnv: envheaderp;
clkQueue: nodep;
allEvents: eventp;
etime: integer;
curtime: integer;
stime: integer;
msg: messagep;
inputp: integer;
*) dum1: array[1..8] of integer;
resched, running, escapeI, iSingleThreadMode: boolean;
msgp: boolean; (* flag set if any messages pending *)
inputReady: boolean;
(* various constant pointers *)
xhat,yhat,zhat,nilvect: dump;
niltrans: dump;
gpark, rpark: dump; (* arm park positions *)
(* various device & variable pointers *)
speedfactor: dump;
garm: dump;
{ Externally defined routines from elsewhere: }
(* From ALLOC *)
function newNode: nodep; external;
procedure relNode(n: nodep); external;
function newVaridef: varidefp; external;
procedure relVaridef(n: varidefp); external;
function newStatement: statementp; external;
procedure relStatement(n: statementp); external;
(* From EROOT: Inter-overlay calls *)
function e3cExprParse: nodep; external;
procedure e3cReParse(st: statementp); external;
(* From EAUX1A *)
function varLookup(id: identp): varidefp; external;
function makeNVar(vartype: datatypes; vid: identp): varidefp; external;
(* From EAUX1B *)
function copyExpr(n: nodep; lcp: boolean): nodep; external;
function defNode(d: datatypes): nodep; external;
procedure appendEnd(s,so: statementp); external;
function checkArg(n: nodep; d: datatypes): nodep; external;
(* From EAUX1C *)
procedure errprnt; external;
function matchdim(d1,d2: nodep; exactp: boolean): boolean; external;
procedure relExpr(n: nodep); external;
(* From EPUT *)
procedure putChar(ch: ascii); external;
procedure putLine; external;
(* From EAUX2A *)
procedure flushVar(oldvar: varidefp); external;
procedure makeNewVar(newvar: varidefp); external;
(* From EAUX2C *)
procedure deleteLines(start,number,coff: integer); external;
procedure insertLines(start,number,coff: integer); external;
(* From EEXPED *)
function exprEditor(line,lstart,llength,estart: integer;
var elength: integer; off: integer): ascii; external;
(* From ETOKEN *)
procedure getToken; external;
procedure getDelim(char: ascii); external;
(* From EPUTST *)
procedure putstmnt(s: statementp; indent, plevel: integer); external;
(* From PP *)
procedure ppLine; external;
procedure ppOutNow; external;
procedure ppChar(ch: ascii); external;
procedure pp5(ch: c5str; length: integer); external;
procedure pp10(ch: cstring; length: integer); external;
procedure pp10L(ch: cstring; length: integer); external;
procedure pp20(ch: c20str; length: integer); external;
procedure pp20L(ch: c20str; length: integer); external;
procedure ppInt(i: integer); external;
procedure ppReal(r: real); external;
procedure ppStrng(length: integer; s: strngp); external;
procedure ppDtype(d: datatypes); external;
procedure ppDelChar; external;
procedure ePar3cGet; external;
procedure ePar3cGet; begin end;
(* aux routines: declarationp, getDeclarations *)
function declarationp: boolean; external;
function declarationp;
var b: boolean; v: varidefp;
begin
b := false;
getToken;
with curToken do
if ttype = reswdtype then
begin
if rtype = decltype then b := true
else if (rtype = optype) and ((op = vmakeop) or (op = vsaxwrop) or
(op = tmakeop) or (op = fmakeop)) then
begin
b := true;
rtype := decltype;
if op = vmakeop then decl := vectype
else if op = vsaxwrop then decl := rottype
else if op = tmakeop then decl := transtype else decl := frametype;
end
else if ((rtype = clsetype) and
((clause = forcetype) or (clause = torquetype) or
(clause = angularvelocitytype) or (clause = velocitytype))) then
begin
b := true;
ttype := identtype;
if clause = forcetype then id := forcedim↑.name
else if clause = torquetype then id := torquedim↑.name
else if clause = velocitytype then id := veldim↑.name
else id := angveldim↑.name;
end
end
else if ttype = identtype then
begin
v := varLookup(id);
if v <> nil then b := v↑.vtype = dimensiontype else b := false;
end;
if not b then backUp := true;
declarationp := b;
end;
function dumDup(v: varidefp): boolean; external;
function dumDup; (* used by routines calling getDeclarations *)
begin dumDup := false end; (* i.e. getDeclarations, procParse & AddDeclSt *)
function getDeclarations(pdef: boolean; lev: integer;
var vo: varidefp; var numvars: integer;
function dup(v: varidefp): boolean): varidefp; external;
function getDeclarations;
var vhdr,va,vp,vdim: varidefp; off,tb,i: integer; d: datatypes;
endlist,b: boolean; no,n: nodep; idname: identp;
function badVarId: boolean;
var v: varidefp; b: boolean;
begin
b := true;
getToken; (* get the id name *)
if curToken.ttype <> identtype then
begin (* garbage *)
pp20L(' Expecting an identi',20); pp10('fier here ',9); errprnt;
backup := true;
b := false;
end
else if pdef then b := true
else
begin
v := curBlock↑.variables;
while (v <> nil) and b do
begin
if v↑.name = curToken.id then b := dup(v);
v := v↑.next;
end;
if not b then
begin (* it's already being used *)
pp20L(' Identifier previous',20); pp20('ly defined in curren',20);
pp10('t block. ',8); errprnt;
end
end;
badVarId := not b;
end;
procedure getSep;
begin
getToken; (* looking for "," or ";" or ")" *)
with curToken do
if ttype = delimtype then
begin
if ch = ',' then endlist := false (* more to get *)
else if pdef and (ch = ')') then backup := true
else if (ch <> ';') and (ch <> chr(15B)) then
begin
pp20L(' Expecting a "," or ',20); pp10('";" here ',8); errprnt;
end
end
else
begin
backup := true;
pp20L(' Inserting missing "',20);
if ttype = identtype then (* user defined dimension type? *)
begin
vp := varLookup(id);
if vp = nil then endlist := false
else if vp↑.vtype <> dimensiontype then endlist := false;
end;
if endlist then ppChar(';') else ppChar(',');
ppChar('"'); errprnt;
end
end;
begin
numvars := 0;
if vo = nil then off := 0 else off := vo↑.offset + 1;
vhdr := nil;
with curToken do
begin
flushcomments := true; (* don't allow comments here *)
b := true;
if pdef then
if (ttype = reswdtype) and (rtype = decltype) and
((decl = reftype) or (decl = valtype)) then
begin (* "reference" or "value" procedure args *)
if decl = valtype then tb := 0 else tb := 4;
b := declarationp; (* get dimension or base type *)
end
else tb := 4 (* pass by "reference" is the default *)
else tb := 0;
if (ttype = identtype) and b then
begin (* deal with dimension info *)
vdim := varLookup(id); (* save it for later *)
b := declarationp; (* get base datatype *)
end
else vdim := nil;
if (not b) or (ttype <> reswdtype) or (rtype <> decltype) or
(decl > arraytype) then
begin (* not a valid basic datatype *)
pp20L(' Need a basic dataty',20); pp10('pe here ',7); errPrnt;
while (not endOfLine) and ((ttype <> delimtype) or (ch <> ';')) do
getToken; (* flush tokens *)
end
else
begin
if decl <> arraytype then d := decl
else
begin
d := undeftype; (* define it later *)
backUp := true;
pp20L(' Need to specify bas',20); pp20('e type of array - wi',20);
pp20('ll try to define it ',20); pp5('later',5); errPrnt;
end;
if d <> proctype then getToken; (* is this really an array or procedure? *)
if (ttype = reswdtype) and (rtype = decltype) and (decl = proctype) then
begin (* new procedure definition *)
if badVarId then idname := nil (* get proc's name & check it's ok *)
else idname := id;
vp := newVaridef;
if vhdr = nil then vhdr := vp;
if vo <> nil then vo↑.next := vp; (* add to list *)
vo := vp;
with vo↑ do
begin
next := nil;
dnext := nil;
name := idname;
level := lev;
offset := off;
off := off + 1;
numvars := numvars + 1;
tbits := 2;
if d = proctype then vtype := nulltype else vtype := d;
dtype := vdim;
n := newNode;
p := n;
end;
with n↑ do
begin
ntype := procdefnode;
ptype := vo↑.vtype;
level := lev + 1;
pname := vo;
paramlist := nil;
getToken; (* see if procedure has any parameters *)
if (ttype = delimtype) and (ch = '(') then (* yup - get 'em *)
begin
va := nil;
while declarationp do (* get parameters *)
begin
vdim := getDeclarations(true,level,va,i,dumDup);
if paramlist = nil then paramlist := vdim;
if (ttype = delimtype) and (ch = ';') then backUp := false;
end;
va := paramlist;
while va <> nil do
with va↑ do begin dnext := next; va := next end;
flushcomments := true; (* don't allow comments again *)
getDelim(')'); (* look for closing ")" *)
getToken; (* get separating ";" *)
end;
backup := (ttype <> delimtype) or (ch <> ';');
body := newStatement;
getToken; (* sneak a look if there's a BEGIN block coming next *)
backup := true;
if (fParse and not sParse) or
((ttype = reswdtype) and (rtype = stmnttype) and
(curToken.stmnt = blocktype)) then (* make an empty stmnt now *)
begin
with body↑ do
begin stype := emptytype; blkid := nil; nlines := 1 end;
end
else
begin (* no body yet - make a Begin-End block *)
appendEnd(body,body);
with body↑ do
begin stype := blocktype; bparent := curBlock; blkid := nil;
nlines := 2; level := lev + 2; numvars := 0; bcode := next;
variables := nil end;
end;
body↑.next := newStatement; (* append a return, just in case *)
with body↑.next↑ do
begin
stype := returntype;
retval := nil;
exprs := nil;
last := n↑.body;
rproc := n;
end;
end;
end
else
begin
if (ttype = reswdtype) and (rtype = decltype) and (decl = arraytype) then
begin
tb := tb + 1; (* we've got an array specification *)
va := nil; (* for list of arrays sharing common bounds list *)
if pdef and (tb = 1) then
begin
tb := 5;
pp20L('Can''t pass arrays by',20); pp20(' value - changing to',20);
pp10(' reference',10); errPrnt;
end
end
else
begin
backUp := true;
if pdef and (tb = 0) and (d = eventtype) then
begin
tb := 4;
pp20L('Can''t pass events by',20); pp20(' value - changing to',20);
pp10(' reference',10); errPrnt;
end
end;
if vdim <> nil then (* check that dimension applies to base type *)
if (d = rottype) and not matchdim(vdim↑.dim,angledim↑.dim,true) then
begin
vdim := nil;
pp20L(' Rotations must be o',20); pp20('f dimension ANGLE ',17);
errPrnt;
end
else if (d = frametype) and
not matchdim(vdim↑.dim,distancedim↑.dim,true) then
begin
vdim := nil;
pp20L(' Frames must be of d',20); pp20('imension DISTANCE ',17);
errPrnt;
end;
repeat
endlist := true; (* assume this is last one *)
if badVarId then
begin (* proc will complain if error *)
if not backup then getSep; (* skip over multiply defined idents *)
end
else
begin (* declare the new variable *)
vp := newVaridef;
if vhdr = nil then vhdr := vp;
if vo <> nil then
with vo↑ do begin next := vp; dnext := vp end; (* add to list *)
vo := vp;
if id↑.predefined <> nil then
if id↑.predefined↑.vtype = pconstype then
begin
pp20L('Redefining predeclar',20); pp20('ed constant - not a ',20);
pp10('good idea ',9); errPrnt;
end;
with vp↑ do
begin
next := nil;
dnext := nil;
name := id;
level := lev;
offset := off;
off := off + 1;
numvars := numvars + 1;
tbits := tb;
vtype := d;
dtype := vdim;
if d = labeltype then s := nil;
end;
if odd(tb) then
begin (* look for array bounds *)
getToken; (* looking for a "[" *)
if (ttype <> delimtype) or (ch <> '[') then
begin (* not yet *)
backUp := true;
vp↑.a := nil; (* no bounds info yet *)
if endOfLine or (ttype = delimtype) and (ch = ';') then
begin (* we aren't going to get one *)
if not pdef then
begin
pp20L(' Expecting an array ',20); pp20('bounds list here ',16);
errPrnt;
vp↑.a := newNode;
with vp↑.a↑ do
begin
ntype := arraydefnode;
combnds := false;
numdims := 1;
bounds := newNode;
with bounds↑ do
begin
ntype := bnddefnode;
next := nil;
lower := defNode(svaltype);
lower↑.s := 1;
upper := defNode(svaltype);
upper↑.s := 10;
end;
end;
end
else va := nil;
end
else if va = nil then va := vp; (* so we can fill things in later *)
end
else
begin (* got one *)
vp↑.a := newNode;
vp↑.a↑.ntype := arraydefnode;
vp↑.a↑.combnds := false;
no := nil;
i := 0;
repeat
n := newNode;
i := i + 1;
with n↑ do
begin
ntype := bnddefnode;
next := nil;
lower := checkArg(e3cExprParse,svaltype); (* get lower bound def *)
getDelim(':'); (* looking for separating ":" *)
upper := checkArg(e3cExprParse,svaltype); (* get upper bound def *)
getToken; (* looking for final "]" or separating "," *)
if (ttype <> delimtype) or ((ch <> ',') and (ch <> ']')) then
begin
pp20L(' Expecting a "," or ',20); pp10('"]" here ',8); errPrnt;
backUp := true;
end;
if no = nil then vp↑.a↑.bounds := n else no↑.next := n;
no := n;
end
until ((ttype = delimtype) and ((ch = ']') or (ch = ';'))) or
(ttype = reswdtype) or endOfLine;
vp↑.a↑.numdims := i;
end;
if vp↑.a <> nil then (* now we can fill things in *)
while va <> nil do
begin
va↑.a := copyexpr(vp↑.a,false); (* copy bounds info *)
va := va↑.next;
if va↑.next = nil then va := nil; (* we already got this one *)
end
end;
getSep; (* looking for "," or ";" or ")" *)
end
until endlist;
end
end;
flushcomments := false; (* comments are ok again *)
end;
backUp := true;
getDeclarations := vhdr;
end;
(* varParse & procParse *)
function varParse(st: statementp; indent,l: integer): ascii; external;
function varParse;
var b,reparsep: boolean; i,j,elen,onumvars: integer; ch: ascii;
v,vhdr,vp,vo: varidefp;
oldvars,newvars: array [1..40] of varidefp; (* 40 should be more than enough... *)
function dupCheck(vo: varidefp): boolean; (* used by getDeclarations *)
var i: integer; b: boolean;
begin
b := false; (* assume no match *)
for i := 1 to onumvars do
if oldvars[i] <> nil then
if vo↑.name = oldvars[i]↑.name then b := true; (* found it? *)
dupCheck := b;
end;
begin
v := st↑.variables;
onumvars := 0;
while v <> nil do
begin (* save pointers to old variable defs *)
onumvars := onumvars + 1;
oldvars[onumvars] := v;
v := v↑.dnext;
end;
(* *** might check if variable was previously undefined, but now is defined
& if so update line on screen with correct info *** *)
with lines[l]↑ do
begin (* edit it *)
elen := length - indent + 1;
if listing[start+length-1] = ';' then begin elen := elen - 1; b := true end
else b := false;
ch := exprEditor(l-firstDline+1,start,length,indent,elen,0);
end;
if b then maxChar := maxChar + 1;
if not declarationp then
begin
pp20L(' Need a declaration ',20); pp5('here ',4); errPrnt;
end
else
begin
vhdr := getDeclarations(false,curBlock↑.level,v,i,dupCheck);
st↑.numvars := i; (* remember # of variables *)
reparsep := false;
v := vhdr;
for i := 1 to st↑.numvars do
begin (* see if old or new variable *)
j := 0;
b := false;
repeat
j := j + 1;
if oldvars[j] <> nil then b := v↑.name = oldvars[j]↑.name;
until b or (j >= onumvars);
if b then
begin (* an old one *)
with oldvars[j]↑ do (* note any changes *)
begin
if dtype <> v↑.dtype then (* see if dimension has changed *)
begin dtype := v↑.dtype; reparsep := true end;
if vtype <> v↑.vtype then (* see if base type has changed *)
begin
vtype := v↑.vtype;
reparsep := true;
(* *** if active block need to change environment entry for variable *** *)
end;
if odd(tbits) then
if a↑.combnds then relNode(a) (* free up any old array bounds *)
else relExpr(a);
if tbits <> v↑.tbits then (* ditto for tbits *)
begin tbits := v↑.tbits; reparsep := true end;
if odd(tbits) then
begin
a := v↑.a; (* copy new array bounds *)
(* *** if active block need to re-evaluate array bounds
& maybe change array size *** *)
end
else if tbits = 2 then
begin (* need to do special stuff for procedure??? *)
p := v↑.p; (* *** deal with proc def ??? *** *)
(* *** if active block need to change environment entry for variable *** *)
end;
end;
newvars[i] := oldvars[j];
oldvars[j] := nil;
end
else
begin (* a new one *)
newvars[i] := makeNVar(v↑.vtype,v↑.name);
with newvars[i]↑ do
begin (* copy relevant fields *)
dtype := v↑.dtype;
tbits := v↑.tbits;
if odd(tbits) then a := v↑.a (* copy array bounds *)
else if tbits = 2 then
begin (* need to do special stuff for procedure??? *)
p := v↑.p; (* *** deal with proc def ??? *** *)
p↑.pname := vp;
end;
end;
makeNewVar(newvars[i]); (* if active block need to make env entry for var *)
reparsep := true;
end;
vp := v↑.dnext;
relVaridef(v); (* all done with the duplicate varidef now *)
v := vp;
if i > 1 then newvars[i-1]↑.dnext := newvars[i];
end;
if st↑.numvars > 0 then
begin
newvars[st↑.numvars]↑.dnext := nil;
st↑.variables := newvars[1];
end
else
begin (* flush declaration *)
with st↑.last↑ do (* splice us out of list *)
if st↑.stype = blocktype then bcode := st↑.next
else next := st↑.next;
st↑.next↑.last := st↑.last;
cursorStack[cursor].st := st↑.next;
deleteLines(cursorLine,1,1);
relStatement(st);
end;
for i := 1 to onumvars do
if oldvars[i] <> nil then
begin reparsep := true; flushVar(oldvars[i]) end;
if reparsep then
begin (* need to reparse block *)
e3cReParse(curBlock);
end;
end;
varParse := ch;
end;
function procParse(n: nodep; indent,l: integer): ascii; external;
function procParse;
var b,reparsep: boolean; i,j,elen,numvars,onumvars,off: integer; ch: ascii;
v,vhdr,vp: varidefp; d: datatypes;
oldvars,newvars: array [1..40] of varidefp; (* 40 should be more than enough... *)
begin
v := n↑.paramlist;
onumvars := 0;
off := 0;
while v <> nil do
begin (* save pointers to old variable defs *)
onumvars := onumvars + 1;
oldvars[onumvars] := v;
if v↑.offset > off then off := v↑.offset; (* find offset for new vars *)
v := v↑.dnext;
end;
(* *** might check if procedure was previously undefined, but now is defined
& if so update line on screen with correct info *** *)
with lines[l]↑ do
begin (* edit it *)
elen := length - indent;
ch := exprEditor(l-firstDline+1,start,length,indent,elen,0);
end;
maxChar := maxChar + 1;
reparsep := false;
with curToken do
begin
flushcomments := true; (* don't allow comments here *)
b := declarationp; (* get the base type *)
if (ttype = identtype) and b then
begin (* deal with dimension info *)
v := varLookup(id); (* save it for later *)
b := declarationp; (* get base datatype *)
end
else v := nil;
if v <> n↑.pname↑.dtype then (* has the dimension changed? *)
begin n↑.pname↑.dtype := v; reparsep := true end;
if (not b) or (ttype <> reswdtype) or (rtype <> decltype) then
begin (* not a valid basic datatype *)
pp20L(' Need a basic dataty',20); pp10('pe here ',7); errPrnt;
end
else
begin
if decl = proctype then d := nulltype else d := decl;
if d <> n↑.pname↑.vtype then (* same base type? *)
begin n↑.pname↑.vtype := d; reparsep := true end;
end;
if d <> nulltype then getToken; (* get procedure token *)
if (ttype <> reswdtype) or (rtype <> decltype) or (decl <> proctype) then
begin
pp20L(' Expecting "procedur',20); pp20('e" here - good luck!',20); errPrnt;
backUp := true; (* *** maybe should do something smart here??? *** *)
end;
getToken; (* get the procedure's name *)
if ttype <> identtype then
begin (* garbage *)
pp20L(' Expecting an identi',20); pp10('fier here ',9); errPrnt;
backUp := true;
end
else if n↑.pname↑.name <> id then
begin (* change the procedure's name *)
n↑.pname↑.name := id; (* *** for now change name & all references to it *** *)
reparsep := true;
end;
getToken; (* see if any parameters *)
numvars := 0;
n↑.paramlist := nil;
if (ttype = delimtype) and (ch = '(') then (* yup - get 'em *)
begin
v := nil;
j := n↑.pname↑.level + 1;
while declarationp do (* get parameters *)
begin
vhdr := getDeclarations(true,j,v,i,dumDup);
numvars := numvars + i; (* remember # of parameters *)
if n↑.paramlist = nil then n↑.paramlist := vhdr;
if (ttype = delimtype) and (ch = ';') then backUp := false;
end;
flushcomments := true; (* don't allow comments again *)
getDelim(')'); (* look for closing ")" *)
end;
end;
v := n↑.paramlist;
for i := 1 to numvars do
begin (* see if old or new variable *)
j := 0;
b := false;
repeat
j := j + 1;
if oldvars[j] <> nil then b := v↑.name = oldvars[j]↑.name;
until b or (j >= onumvars);
if b then
begin (* an old one *)
with oldvars[j]↑ do (* note any changes *)
begin
if dtype <> v↑.dtype then (* see if dimension has changed *)
begin dtype := v↑.dtype; reparsep := true end;
if vtype <> v↑.vtype then (* see if base type has changed *)
begin
vtype := v↑.vtype;
reparsep := true;
(* *** if active procedure need to change environment entry for variable *** *)
end;
if odd(tbits) then relExpr(a); (* free up any old array bounds *)
if tbits <> v↑.tbits then (* ditto for tbits *)
begin tbits := v↑.tbits; reparsep := true end;
if odd(tbits) then
begin
a := v↑.a; (* copy new array bounds *)
end;
end;
newvars[i] := oldvars[j];
oldvars[j] := nil;
vp := v↑.next;
relVaridef(v); (* all done with the duplicate varidef now *)
v := vp;
end
else
begin (* a new one *)
newvars[i] := v;
off := off + 1;
v↑.offset := off;
(* *** if active procedure need to create environment entry for variable *** *)
reparsep := true;
v := v↑.next;
end;
if i > 1 then
with newvars[i-1]↑ do begin next := newvars[i]; dnext := next end;
end;
if numvars > 0 then
begin
newvars[numvars]↑.next := nil;
newvars[numvars]↑.dnext := nil;
n↑.paramlist := newvars[1];
(* if not active-now then *)
begin (* renumber variable offsets *)
for i := 1 to numvars - 1 do
with newvars[i]↑ do
begin
next := newvars[i+1];
offset := i-1;
end;
newvars[numvars]↑.next := nil;
end;
end
else n↑.paramlist := nil;
for i := 1 to onumvars do
if oldvars[i] <> nil then
with oldvars[i]↑ do
begin (* flush old unused variables *)
(* *** if active procedure flush its value *** *)
if odd(tbits) then relExpr(a); (* free up old array bounds list *)
relVaridef(oldvars[i]);
reparsep := true;
end;
if reparsep then
begin (* need to reparse procedure body *)
e3cReParse(n↑.body);
end;
procParse := ch;
end;